package com.game.state;

import javax.microedition.khronos.opengles.GL10;

import system.FPSCalculate;
import system.Graphics;
import system.MyCamera;
import android.content.Context;

import com.game.GamePlay;
import com.game.level.Mission;
import com.game.level.Mission1;
import com.game.level.MissionStatus;

public class InGame extends State {

	private GL10 gl;
	private Context m_context;
	private float m_fSrcWidth;
	private float m_fSrcHeight;
	FPSCalculate fps;
	
	
	private int m_iMaxLevel = 1;
//	Teminator ter;
	
	int m_iSubState = 0;
	
	static Mission s_currentMission;
	int m_iMissionID = 1;

	@Override
	public void Init() {
		fps = new FPSCalculate();
		this.SetKeyBoardDelay(0);	

		MyCamera.InitCamera(Graphics.GetGraphics(), 100, 180);
//		GUIGame.Init();
		//Camera.SetCamera(gl, 90, 180);

//		gl.glMatrixMode(GL10.GL_PROJECTION);
//		gl.glPushMatrix();
//		gl.glMatrixMode(GL10.GL_MODELVIEW);
//		gl.glPushMatrix();
		Graphics.GetGraphics().glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);	
		
//		gl.glEnable(GL10.GL_TEXTURE_2D);
		s_currentMission = new Mission1();
		m_bReadyResources = true;
	}
	
	@Override
	public void Update(GamePlay gamePlay) {
		
		if (!m_bReadyResources){
//			LoadingResources();
			return;
		}
		super.Update(gamePlay);
//		ter.Update();
		if (s_currentMission.GetStatus() == MissionStatus.COMPLETED){
			++m_iMissionID;
			switch (m_iMissionID){
			case 2:
				break;
			case 3:
				break;
			default:
				// change to mission complete and new mission	
			}
		}
		s_currentMission.Update(gamePlay);		
	}
	
	private float m_alphaShooting;
	private float m_betaShooting;
	
	@Override
	public void Render() {
		
		if (!m_bReadyResources)
			return;
//		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
//		gl.glClearColor(0.4706f, 0.6706f, 0.9137f, 0.8f);
		s_currentMission.Render();
		
		fps.CurrentTime = System.currentTimeMillis();
		fps.updateFPS();
		System.out.println("\n FPS=" + fps.FPSAverage);
		fps.LastTime = fps.CurrentTime;
	}

	@Override
	public void Destroy() {
		s_currentMission.Destroy();
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glPopMatrix();
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glPopMatrix();
	}


	@Override
	public void ProcessKeyboard(GamePlay gamePlay) {
		// TODO Auto-generated method stub
		s_currentMission.ProcessKeyboard(gamePlay);
	}
}
